<?php

class Memcache{

	private $mem;

	/** 
    * Memcache 构造方法 
    * @param   array    $mem_servers    Associative array of settings 
    * @return  mixed 
    * @access  public 
    */ 
	public function __construct($memcache_servers) 
    {
		$this->mem = new Memcache;
		foreach((array)$memcache_servers as $kk=>$vv)
		{
			$this->mem->addServer($vv['host'], $vv['port']);
		}
    } 
	
	/** 
    * Memcache 初始化方法 
    * @param   array    $mem_servers    Associative array of settings 
    * @return  mixed 
    * @access  public 
    */ 
	public static function getInstance()
    {
		global $memcache_servers;
        static $instance;
        if(!$instance){
            $instance = new self($memcache_servers);
        }
        return $instance;
    }

	/** 
    * Memcache get
    */ 
	public function get($id)
	{
		$info = $this->mem->get("searchInfo:id_" . $id);
		
		return $info;
	}
    
    /** 
    * Memcache del 
    */ 
    public function del($id)
    {
        return $this->mem->delete("searchInfo:id_" . $id);
    }

	/** 
    * Memcache set 
    */ 
    public function set($id,$val){
		$info = $this->mem->set("searchInfo:id_".$id, $val, MEMCACHE_COMPRESSED, CACHE_MINUTE * 15);

        return $info ? $info : array();
	}
}

?>